package com.ruoyi.kws.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.kws.domain.CountData;
import com.ruoyi.kws.service.ICountDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据统计Controller
 *
 * @author wfc
 * @date 2025-02-01
 */
@RestController
@RequestMapping("/kws/data")
public class CountDataController extends BaseController
{
    @Autowired
    private ICountDataService countDataService;

    /**
     * 查询数据统计列表
     */
    @PreAuthorize("@ss.hasPermi('kws:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(CountData countData)
    {
        startPage();
        List<CountData> list = countDataService.selectCountDataList(countData);
        return getDataTable(list);
    }

    /**
     * 导出数据统计列表
     */
    @PreAuthorize("@ss.hasPermi('kws:data:export')")
    @Log(title = "数据统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CountData countData)
    {
        List<CountData> list = countDataService.selectCountDataList(countData);
        ExcelUtil<CountData> util = new ExcelUtil<CountData>(CountData.class);
        util.exportExcel(response, list, "数据统计数据");
    }

    /**
     * 获取数据统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('kws:data:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(countDataService.selectCountDataById(id));
    }

    /**
     * 新增数据统计
     */
    @PreAuthorize("@ss.hasPermi('kws:data:add')")
    @Log(title = "数据统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CountData countData)
    {
        if(countDataService.insertCountData(countData)>0){
            return AjaxResult.success("操作成功");
        }else{
            return AjaxResult.error("操作失败，请检查日期[日期不能重复]");
        }
    }

    /**
     * 修改数据统计
     */
    @PreAuthorize("@ss.hasPermi('kws:data:edit')")
    @Log(title = "数据统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CountData countData)
    {
        return toAjax(countDataService.updateCountData(countData));
    }

    /**
     * 删除数据统计
     */
    @PreAuthorize("@ss.hasPermi('kws:data:remove')")
    @Log(title = "数据统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(countDataService.deleteCountDataByIds(ids));
    }
}
